package org.glut.service;

import org.glut.bean.RF;
import org.glut.serialport.manager.SerialPortManager;
import org.glut.serialport.ui.MainFrame;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Scope("singleton")
public class RFService {
    @Autowired
    MessageService messageService;
    //    @Autowired
//    private  static MainFrame mainFrame;
    @Autowired
    public static RF rf1;
    public static RF rf2;
    public List<String> rftimeList1 = new ArrayList<>();
    public List<String> rfpower1 = new ArrayList<>();
    public List<String> rftimeList2 = new ArrayList<>();
    public List<String> rfpower2 = new ArrayList<>();
    private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//设置时间

    public RFService() {
        rf1 = new RF();
        rf2 = new RF();
//        (CF)GetApplicationContext.getBean("CF")
    }


    public void getmsgs(String[] message) {
//        for (String s : message) {
//            System.out.println(s);
//        }
//        rf = (CF) GetApplicationContext.getBean("CF");
        char id = message[0].charAt(2);
        if (id == '1') {
            initYH(rf1,message,rftimeList1,rfpower1);
        } else if (id == '2') {
            initYH(rf2,message,rftimeList2,rfpower2);
        }


//            System.out.println(timeList);
//            System.out.println(rfList);
    }

    private void initYH(RF rf, String[] message, List<String> rftimeList,  List<String> rfpower) {
        rf.setId(message[0].charAt(2)+"");
        rf.setPower(message[1].substring(1));
        rf.setCurNum(message[2].substring(1));
        rf.setStatus(message[3].substring(1));
        String time = df.format(new Date());
        rftimeList.add(time);
        rfpower.add(rf.getPower());
    }

}
